﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using T6._1.Models;

namespace T6._1.Controllers
{
    public class HomeController : Controller
    {
        // GET: Home
        //示例
        public ActionResult Index()
        {
            using (fashionshoppingDBEntities db=new fashionshoppingDBEntities())
            {
                //IEnumerable<Product> plist = db.Products.ToList();
                return View(db.Products.Include("Procate").ToList());//贪婪加载
            }            
        }
        //登录get
        public ActionResult Login()
        {
            return View();
        }
        [HttpPost]
        //登录get
        public ActionResult Login(Sysuser admin)
        {
            using (fashionshoppingDBEntities db = new fashionshoppingDBEntities())
            {
                if (ModelState.IsValid)
                {
                    //    User login = db.Users.FirstOrDefault(u => u.email == user.email && u.pwd == user.pwd);
                    //    if (login==null)
                    //    {
                    //        ModelState.AddModelError("", "邮箱或密码错误");
                    //    }
                    //    else
                    //    {
                    //        return RedirectToAction("Index");
                    //    }
                    //}
                    var u = db.Sysusers.FirstOrDefault(x => x.username == admin.username && x.pwd == admin.pwd);
                    if (u == null)
                    {
                        ModelState.AddModelError("", "账号或密码错误");
                    }
                }
                return View();
            }
        }










        //实践作业6.1
        public ActionResult User()
        {
            using (fashionshoppingDBEntities db=new fashionshoppingDBEntities())
            {
                var users = db.Users.ToList();
                return View(users);
            }
        }

        //实践作业6.2
    }
}